#ifndef ABSTRACTSECTIONMODEL_H
#define ABSTRACTSECTIONMODEL_H

#include <QAbstractItemModel>

template <typename Type> class GraphNode;
class QAbstractItemDelegate;
class SectionInfo;
class ValueResult;

class AbstractSectionModel : public QAbstractTableModel
{
    Q_OBJECT
public:
    explicit AbstractSectionModel(QObject *parent = 0);

    virtual QVariant id (int row, int column = 0) const;
    virtual QVariantList ids (QList<int> rows) const;
    virtual QMap<int,QAbstractItemDelegate*> delegates() const;
    virtual QStringList headerSectionsForAdding() const;
    virtual QList<QAbstractItemDelegate*> delegatesForAdding() const;
    virtual ValueResult* canAddData (QVariantList dataList);
    virtual ValueResult* canUpdateData (QVariant value, int row, int column);
    virtual ValueResult* canSetField (QVariant value, int column, int row = -1);
    virtual ValueResult* canSetRow (QVariantList dataList, int row = -1);
    virtual QVariant correctedValue (QVariant value, int column) const;
    virtual bool isEditingEnabled() const;
    virtual SectionInfo sectionInfo() const;

    virtual int rowCount (const QModelIndex &parent = QModelIndex()) const = 0;
    virtual int columnCount (const QModelIndex &parent = QModelIndex()) const = 0;
    virtual QVariant data (const QModelIndex &index, int role = Qt::DisplayRole) const = 0;
    virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const = 0;
    virtual Qt::ItemFlags flags(const QModelIndex &index) const;

public slots:
    virtual void initialize() {}
    virtual void loadData();
    virtual void loadData (bool result);
    virtual void addData (QVariantList dataList);
    virtual void updateData (QVariant data, int row, int column);
    virtual void removeData (QVariantList dataList);
    virtual void removeData (QVariant data);
    virtual void setSectionInfo(const SectionInfo &sectionInfo);
    virtual void setLoadingParameters (QVariantList parameters);
    virtual void setEditingEnabled (bool enabled);
    virtual void setReloadAfterModification (bool enabled);

signals:
    void initialized();
    void loadDataFinished (bool result);
    void addDataFinished (bool result);
    void updateDataFinished (bool result);
    void removeDataFinished (bool result);
    void delegatesAboutToBeChanged();
    void delegatesChanged();
    void notifyHint (QString title, QString message);
    void notifyInformation (QString title, QString message);
    void notifyWarning (QString title, QString message);

protected:
    bool m_isModelEditable;
    bool m_isEditingCurrentlyEnabled;
    bool m_reloadAfterModification;
};

#endif // ABSTRACTSECTIONMODEL_H

